package Game;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.*;

import GUIInterfaces.OregonPanel;
import GUIInterfaces.OregonWindow;

import java.util.*;

/**
 * 
 */

/**
 * @author William Kurkian
 *	This panel works by passing it the gamedriver and generating the store.
 *	It expects the window above it to implement OregonWindow and it has oregon panel
 */
public class WinPanel extends JPanel implements ActionListener,OregonPanel {
	
	GameDriver gd;
	OregonWindow parent;
	BufferedImage background;
	JButton playAgain = new JButton();
	
	
	/*
	 * The constructor creates the components and initializes everything.
	 */
	public WinPanel(OregonWindow parent) {
		this.parent = parent;
		this.setLayout(null);
		
		configureButton(playAgain,new Rectangle(225,415,315,85));
		
		add(playAgain);
		String folder = System.getProperty("user.dir")+ File.separator + "images" + File.separator;
		try {
			background = ImageIO.read(new File(folder+"congrats.png"));
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, "Congrats.png could not be loaded.");
		}
	}

	/**
	 * Method to configure buttons. It makes them invisible and sets their bounds to rectangle.
	 * @param button
	 * @param rectangle
	 */
	private void configureButton(JButton button, Rectangle rectangle) {
		button.setBounds(rectangle);
		//button.setOpaque(false);
		button.setContentAreaFilled(false);
		button.setBorderPainted(false);
		button.addActionListener(this);
		
	}

	
	public void paintComponent(Graphics g) {
		g.drawImage(background,0,0,null);
		
	}
	/**
	 * This method allows the parent to set the game driver after initialization
	 * so the panel can be initalized before the caravan is ready.
	 * This is from the OregonPanel.
	 * @param gd
	 */
	public void setGameDriver(GameDriver gd) {
		this.gd = gd;
		
		
	}
	
	@Override
	
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource() == playAgain) {
			parent.done(this);
		}
		
	}

	/*
	 * Sets the game driver
	 * @see OregonPanel#getGameDriver()
	 */
	public GameDriver getGameDriver() {
		return gd;
	}

	@Override
	/*
	 * Gets the crrent propery. Uniplemented here.
	 * @see OregonPanel#getProperty()
	 */
	public String getProperty() {
		// TODO Auto-generated method stub
		return null;
	}
}
